const requests = require("./utils/request")

const personalCloudEnv = "trashrecycle-core-4e1w8p237dea1b"
const cloudEnv = "trashrecycle-core-0eiz3s5fc13519"
App({
  onLaunch() {
    var that = this

    /**
     * 开启云服务
     */
    wx.cloud.init({
            env:cloudEnv
          })

      /**
       * 计算导航栏高度
       */
      // 状态栏高度
      const { statusBarHeight, platform } = wx.getSystemInfoSync()
      const { top, height } = wx.getMenuButtonBoundingClientRect()
      // 胶囊按钮高度 一般是32 如果获取不到就使用32
      const menuButtonHeight = height ? height : 32
      let navigationBarHeight
      // 判断胶囊按钮信息是否成功获取
      if (top && top !== 0 && height && height !== 0) {
        navigationBarHeight = (top - statusBarHeight) * 2 + height
        // 导航栏高度
        } else {
          navigationBarHeight = platform === 'android' ? 48 : 40
      }
      this.globalData.navigationBarHeight=navigationBarHeight
      this.globalData.statusBarHeight=statusBarHeight

      //下载导航栏的gif
      requests.downloadFile('static/wave.gif').then((res)=>{
        that.globalData.wavegif=res
      })


  },
  globalData: {
    orderPageActive:0,//订单页哪一页首先展示
    userInfo: null,
    openid:"",
    sysWidth:wx.getSystemInfoSync().windowWidth, //图片宽度
    // imgUrlPre:'http://81.68.205.39:9000/image/',
    navigationBarHeight:null,
    wavegif:'',//导航栏需要的gif
  },

  //定义动画
   //渐入，渐出实现 
  show : function(that,param,opacity){
    var animation = wx.createAnimation({
      //持续时间800ms
      duration: 2000,
      timingFunction: 'ease',
    });
    //var animation = this.animation
    animation.opacity(opacity).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
  },
  slideupshow:function(that,param,px,opacity)
  {
    // console.log(px,opacity)
    var animation = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease',
    })
    animation.translateY(px).step()
    // console.log(animation)
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    // console.log(json)
    that.setData(json)
  },
  //向右滑动渐入渐出
  sliderightshow: function (that, param, px, opacity) {
    var animation = wx.createAnimation({
      duration: 2000,
      timingFunction: 'ease',
    });
    animation.translateX(px).opacity(opacity).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
  }

})
